import {
  AccountParams,
  DeptListItem,
  MenuParams,
  RoleParams,
  RolePageParams,
  MenuListGetResultModel,
  DeptListGetResultModel,
  AccountListGetResultModel,
  RolePageListGetResultModel,
  RoleListGetResultModel,
} from './model/systemModel';
import { defHttp, jsonHttp } from '@/utils/http/axios';
import { BasicDataResult } from '../model/baseModel';
import { ErrorMessageMode } from '#/axios';
enum Api {
  AccountList = '/system/getAccountList',
  IsAccountExist = '/system/accountExist',
  DeptList = '/system/getDeptList',
  setRoleStatus = '/system/setRoleStatus',
  MenuList = '/hl/sys/menu/menuList',
  saveMenu = '/hl/sys/menu/saveMenu',
  menuDelete = '/hl/sys/menu/menuDelete',
  getMenuTreeList = '/hl/sys/menu/getMenuTreeList',

  RolePageList = '/hl/sys/menu/roleList',
  GetAllRoleList = '/hl/sys/menu/roleSelectList',

  saveRole = '/hl/sys/menu/saveRole',
  roleDetail = '/hl/sys/menu/roleDetail',
  roleDelete = '/hl/sys/menu/roleDelete',

  sysAccountList = '/hl/sys/account/list',
  sysAccountSave = '/hl/sys/account/save',
  sysAccountDelete = '/hl/sys/account/delete',
}

export const getAccountList = (params: AccountParams) =>
  defHttp.get<AccountListGetResultModel>({ url: Api.AccountList, params });

export const getDeptList = (params?: DeptListItem) =>
  defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });

export function getMenuList(params: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.MenuList,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function saveMenu(params: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.saveMenu,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function menuDelete(params: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.menuDelete,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export function getMenuTreeList(params: any, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<BasicDataResult>(
    {
      url: Api.getMenuTreeList,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export const getRoleListByPage = (params?: any) =>
  defHttp.post<RolePageListGetResultModel>({ url: Api.RolePageList, params });

export const getAllRoleList = (params?: any) =>
  defHttp.post<RoleListGetResultModel>({ url: Api.GetAllRoleList, params });

export const setRoleStatus = (id: number, status: string) =>
  defHttp.post({ url: Api.setRoleStatus, params: { id, status } });

export const isAccountExist = (account: string) =>
  defHttp.post({ url: Api.IsAccountExist, params: { account } }, { errorMessageMode: 'none' });

export const saveRole = (params?: any) =>
  defHttp.post<RoleListGetResultModel>({ url: Api.saveRole, params });

export const roleDetail = (params?: any) =>
  defHttp.post<RoleListGetResultModel>({ url: Api.roleDetail, params });

export const roleDelete = (params?: any) =>
  defHttp.post<RoleListGetResultModel>({ url: Api.roleDelete, params });

export const sysAccountList = (params?: any) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.sysAccountList, params });

export const sysAccountSave = (params?: any) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.sysAccountSave, params });

export const sysAccountDelete = (params?: any) =>
  defHttp.post<AccountListGetResultModel>({ url: Api.sysAccountDelete, params });
